<script>
  // 判断右边构造函数的原型对象是否存在于左边对象的原型链上
  function _instaceof(obj, ctor) {
    // 左边必须是对象
    /* 
       1 instaceOf Number -> false
       Number(1) instaceOf Number -> false
     */
    if (!(obj && typeof obj === 'object')) {
      return false
    }

    let proto
    while (proto = Object.getPrototypeOf(obj)) {
      if (Object.is(proto, ctor.prototype)) {
        return true
      }
      obj = proto
    }
  }


  // 测试
  let Fn = function () {}
  let p1 = new Fn()

  console.log(_instaceof({}, Object)) // true
  console.log(_instaceof(p1, Fn)) // true
  console.log(_instaceof({}, Fn)) // false
  console.log(_instaceof(null, Fn)) // false
  console.log(_instaceof(1, Fn)) // false
</script>